<!DOCTYPE html>
<html>
<head>
<title>商家登记</title>
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="format-detection" content="telephone=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />

<link rel="stylesheet" href="assets/css/amazeui.min.css" />

<script src="assets/js/jquery.min.js" type="text/javascript"></script>
<script src="assets/js/amazeui.min.js" type="text/javascript"></script>
<script src="js/main.js" type="text/javascript"></script>
<script src="js/md5.js" type="text/javascript"></script>
<style type="text/css">
.divcss6 {
	border: 2px dashed #e6e6e6;
	padding: 1em 1em 1em 1em;
}

  #vld-tooltip {
    position: absolute;
    z-index: 1000;
    padding: 5px 10px;
    background: #F37B1D;
    min-width: 150px;
    color: #fff;
    transition: all 0.15s;
    box-shadow: 0 0 5px rgba(0,0,0,.15);
    display: none;
  }

  #vld-tooltip:before {
    position: absolute;
    top: -8px;
    left: 50%;
    width: 0;
    height: 0;
    margin-left: -8px;
    content: "";
    border-width: 0 8px 8px;
    border-color: transparent transparent #F37B1D;
    border-style: none inset solid;
  }

</style>

<script type="text/javascript">
	$(function() {
		getPaintBrandList();
		getQuotationList();
		toEditForm();
		doFormValidate('form');
	});

	function editCarService(domid, carType){
		if (carType) {
			$carObj = $("#" + domid);
			var singlepaintprices = carType.singlepaintprices;
			var sheetmetalprices=carType.sheetmetalprices;
			$singlepaintpriceObj=$("#" + domid + " div[title='singlepaintprices']");
			$sheetmetalpricesObj=$("#" + domid + " div[title='sheetmetalprices']");	
			//console.log($("#" + domid + " div[title='sheetmetalprices']").find("input[name='level0']"));
			$.each(singlepaintprices, function(key, value) {				
				$singlepaintpriceObj.find("input[name='"+value.name+"']").val(value.price);
			});	
			$.each(sheetmetalprices, function(key, value) {
				$sheetmetalpricesObj.find("input[name='"+value.name+"']").val(value.price);
			});
			$carObj.find("select[name='paintbrand']").val(carType.paintbrandid);
			$carObj.find("input[name='ispaintpartly'][value="+carType.ispaintpartly+"]").prop('checked',true); 
			$carObj.find("input[name='hasholidayprice'][value="+carType.hasholidayprice+"]").prop('checked',true); 
			$carObj.find("input[name='hasfeewash'][value="+carType.hasfeewash+"]").prop('checked',true); 
			$carObj.find("input[name='holidaydiscount']").val(carType.holidaydiscount);	
		}
	}
	function toEditForm(){
		var merchant=getSessionValue('mdetail');
		merchant=JSON.parse(merchant);	
		if(merchant){
			editCarService('commonpaint',merchant.commonpaint);
			editCarService('mediumpaint',merchant.mediumpaint);
			editCarService('advancedpaint',merchant.advancedpaint);
		}
	}
	function toEditPricesArray(domid, priceType){
		var prices = new Array();
		$("#" + domid + " div[title='" + priceType + "'] :input").each(
				function() {
					var obj = {
						name : this.name,
						description:this.title,
						price : this.value
					};
					prices.push(obj);
				});
		return prices;
	}
	function getQuotationList() {
		var quotationList = baseLoad('getQuotationList.action', 'quotationList');
		if (quotationList) {
			var qList = JSON.parse(quotationList);
			var content = "";
			$.each(	qList,
							function(key, value) {
								content += '<div class="am-form-group">'
								content += '<div class="am-u-sm-3">';
								content += '<label for="name" style="margin-top: 0.8em">'
										+ value.description + ':</label></div>';
								content += '<div class="am-u-sm-9">'
								content += '<input type="text" class="am-form-field" title="'+value.description+'" name="'+value.name+'"/></div></div>';
							});
		
			$(".divcss5").append(content);
		}
	}

	function getPaintBrandList() {
		var paintBrandList = baseLoad('getPaintBrandList.action',
				'paintBrandList');
		if (paintBrandList) {
			var paintList = JSON.parse(paintBrandList);
			var content = "";
			$.each(paintList, function(key, value) {
				content += "<option value='"+value.paintbrandid+"'>"
						+ value.paintbrandname + "</option>";
			});
			$(".paintbrand").append(content);
		}
	}
	function pricesArray(domid) {
		var prices = new Array();
		$("#" + domid + " :input").each(function() {
			var obj = {
				name : this.name,
				description:this.title,
				price : this.value
			};
			prices.push(obj);
		});
		return prices;
	}

	function toPricesArray(domid, priceType) {
		var prices = new Array();
		$("#" + domid + " div[title='" + priceType + "'] :input").each(
				function() {
					var obj = {
						name : this.name,
						description:this.title,
						price : this.value
					};
					prices.push(obj);
				});
		return prices;
	}
	function toFormObject(formid) {//var paintbrandid=$("#"+formid+" select[name='paintbrand']").val();
		var paint = new Object();
		$formObject = $("#" + formid);
		paint.paintbrandid = $formObject.find("select[name='paintbrand']").val();
		paint.paintbrandname = $formObject.find("select[name='paintbrand']").find("option:selected").text();
		paint.ispaintpartly = $formObject.find("input[name='ispaintpartly']").val();
		paint.hasholidayprice = $formObject.find("input[name='hasholidayprice']").val();
		paint.hasfeewash = $formObject.find("input[name='hasfeewash']").val();
		paint.holidaydiscount = $formObject.find("input[name='holidaydiscount']").val();
		paint.singlepaintprices = toPricesArray(formid, 'singlepaintprices');
		paint.sheetmetalprices = toPricesArray(formid, 'sheetmetalprices');
		return paint;
	}
	function doSubmit(type){
		var flag=true;
		$('form').each(function(){
			flag=$(this).validator('isFormValid');		
			if(!flag){
				return false;
			}
		});
		if(flag){
			saveToNext(type);
			
		}
		
	}
	function saveToNext(type) {
		popLoading();
		var reqData = new RequestData('register2.action');
		var commonpaint = toFormObject('commonpaint');
		var mediumpaint = toFormObject('mediumpaint');
		var advancedpaint = toFormObject('advancedpaint');
		reqData.commonpaint = commonpaint;
		reqData.mediumpaint = mediumpaint;
		reqData.advancedpaint = advancedpaint;
		var merchantid = getSessionValue("merchantid");
		if (merchantid) {
			reqData.merchantid = merchantid;
		} else {
			reqData.merchantid = "";
		}
		var jsonstr = JSON.stringify(reqData);
	
		$.ajax({
			cache : false,
			type : "POST",
			crossDomain : true,
			url : testUrl,
			data : jsonstr, //你的formid
			async : false,
			error : function(request) {
				closeLoading();
				popAlert("Connection error");
			},
			success : function(data) {
				var dataObj = eval("(" + data + ")");
				if (dataObj.ret == 1) {
					window.sessionStorage.setItem("register2", jsonstr);
					closeLoading();
					if(type=='snext'){
						location.href = "mregister3.html";
					}else{
						closeLoading();
						popAlert('保存成功!');
					}
					
				}
			}
		});
	}

	/* 返回上一页 */
	function backPrepage() {	
		if (window.document.referrer.indexOf("mregister1.html")==-1) {
			history.go(-2);
		} else {
			window.location.href = window.document.referrer;
		}
	}
	
</script>
</head>

<body>
	<header data-am-widget="header" class="am-header am-header-default am-header-fixed">
		<div class="am-header-left am-header-nav">
			<a href="javascript: void(0)"  onclick="javascript:history.back()"> <i
				class="am-header-icon am-icon-chevron-left"></i>
			</a>
		</div>
		<h1 class="am-header-title">
			<a href="#title-link" class=""> 车夫登记2/4 </a>
		</h1>

	</header>
	<div class="am-g" id="pageHome">

		<section data-am-widget="accordion"
			class="am-accordion am-accordion-gapped" data-am-accordion='{ }'>
			<dl class="am-accordion-item am-active">
				<dt class="am-accordion-title">20万以下车型</dt>
				<dd class="am-accordion-bd am-collapse am-in">
					<div class="am-accordion-content">
						<form id="commonpaint" class="am-form am-form-horizontal">
							<fieldset>
								<div class="am-form-group">
									<div class="am-u-sm-3">
										<label for="paintbrand">车漆品牌</label>
									</div>
									<div class="am-u-sm-9">
										<select name="paintbrand" class="paintbrand"></select>
									</div>
								</div>
								<section class="am-panel am-panel-default">
									<header class="am-panel-hd">
										<h3 class="am-panel-title">
											<label for="name">单幅车漆价格</label>
										</h3>
									</header>
									<div class="am-panel-bd divcss5" title="singlepaintprices"></div>
								</section>
								<section class="am-panel am-panel-default">
									<header class="am-panel-hd">
										<h3 class="am-panel-title">
											<label for="name">铂金价格</label>
										</h3>
									</header>
									<div class="am-panel-bd divcss5" title="sheetmetalprices"></div>
								</section>

										<div class="am-form-group">
										<label for="paintbrand">局部喷漆</label>				
										<div class="am-form-group">
											 <label class="am-radio-inline">
												<input type="radio" name="ispaintpartly" value="1" data-am-ucheck  /> 是
											</label>
											<label class="am-radio-inline">
												<input type="radio" name="ispaintpartly" value="0" data-am-ucheck /> 否</label>
										</div>
									</div>
									<div class="am-form-group">						
										<label for="paintbrand">包含免费洗车服务</label>	
										<div class="am-form-group">
											 <label class="am-radio-inline">
												<input type="radio" name="hasfeewash" value="1" data-am-ucheck  /> 是
											</label>
											<label class="am-radio-inline">
												<input type="radio" name="hasfeewash" value="0" data-am-ucheck /> 否</label>
										</div>
									</div>
									<div class="am-form-group">		
										<label for="name">分节假日不同价钱</label>
							
										<div class="am-form-group">
											 <label class="am-radio-inline">
												<input type="radio" name="hasholidayprice" value="1" data-am-ucheck  /> 是
											</label>
											<label class="am-radio-inline">
												<input type="radio" name="hasholidayprice" value="0" data-am-ucheck /> 否</label>
										</div>
									</div>
									<div class="am-form-group">		
									<div class="am-u-sm-4">
										<label for="name">节假日折扣</label>
									</div>
									<div class="am-u-sm-8">
										<input type="number"  name="holidaydiscount"   min="0" max="10" 
											 data-foolish-msg="把 IQ 卡密码交出来！" placeholder="折">
									</div>
								</div>	
							</fieldset>
						</form>
					</div>
				</dd>
			</dl>
			<dl class="am-accordion-item">
				<dt class="am-accordion-title">20-40万车型</dt>
				<dd class="am-accordion-bd am-collapse ">
					<div class="am-accordion-content">
						<form id="mediumpaint" class="am-form am-form-horizontal" action="">
							<fieldset>
								<div class="am-form-group">
									<div class="am-u-sm-3">
										<label for="paintbrand">车漆品牌</label>
									</div>
									<div class="am-u-sm-9">
										<select name="paintbrand" class="paintbrand"></select>
									</div>
								</div>
								<section class="am-panel am-panel-default">
									<header class="am-panel-hd">
										<h3 class="am-panel-title">
											<label for="name">单幅车漆价格：</label>
										</h3>
									</header>
									<div class="am-panel-bd divcss5" title="singlepaintprices"></div>
								</section>
								<section class="am-panel am-panel-default">
									<header class="am-panel-hd">
										<h3 class="am-panel-title">
											<label for="name">铂金价格</label>
										</h3>
									</header>
									<div class="am-panel-bd divcss5" title="sheetmetalprices"></div>
								</section>
													<div class="am-form-group">
										<label for="paintbrand">局部喷漆</label>				
										<div class="am-form-group">
											 <label class="am-radio-inline">
												<input type="radio" name="ispaintpartly" value="1" data-am-ucheck  /> 是
											</label>
											<label class="am-radio-inline">
												<input type="radio" name="ispaintpartly" value="0" data-am-ucheck /> 否</label>
										</div>
									</div>
									<div class="am-form-group">						
										<label for="paintbrand">包含免费洗车服务</label>	
										<div class="am-form-group">
											 <label class="am-radio-inline">
												<input type="radio" name="hasfeewash" value="1" data-am-ucheck  /> 是
											</label>
											<label class="am-radio-inline">
												<input type="radio" name="hasfeewash" value="0" data-am-ucheck /> 否</label>
										</div>
									</div>
									<div class="am-form-group">		
										<label for="name">分节假日不同价钱</label>
							
										<div class="am-form-group">
											 <label class="am-radio-inline">
												<input type="radio" name="hasholidayprice" value="1" data-am-ucheck  /> 是
											</label>
											<label class="am-radio-inline">
												<input type="radio" name="hasholidayprice" value="0" data-am-ucheck /> 否</label>
										</div>
									</div>
									<div class="am-form-group">		
									<div class="am-u-sm-4">
										<label for="name">节假日折扣</label>
									</div>
									<div class="am-u-sm-8">
										<input type="number" name="holidaydiscount"  value=""
											data-mini="true" placeholder="折">
									</div>
								</div>	
							</fieldset>
						</form>
					</div>
				</dd>
			</dl>
			<dl class="am-accordion-item">
				<dt class="am-accordion-title">40万以上车型</dt>
				<dd class="am-accordion-bd am-collapse ">
					<!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题， 加一个容器 -->
					<div class="am-accordion-content">
						<form id="advancedpaint" class="am-form am-form-horizontal" action="">
						
								<div class="am-form-group">
									<div class="am-u-sm-3">
										<label for="paintbrand">车漆品牌</label>
									</div>
									<div class="am-u-sm-9">
										<select name="paintbrand" class="paintbrand"></select>
									</div>
								</div>
								<section class="am-panel am-panel-default">
									<header class="am-panel-hd">
										<h3 class="am-panel-title">
											<label for="name">单幅车漆价格：</label>
										</h3>
									</header>
									<div class="am-panel-bd divcss5" title="singlepaintprices"></div>
								</section>
								<section class="am-panel am-panel-default">
									<header class="am-panel-hd">
										<h3 class="am-panel-title">
											<label for="name">铂金价格</label>
										</h3>
									</header>
									<div class="am-panel-bd divcss5" title="sheetmetalprices"></div>
								</section>

								<div class="am-form-group">
										<label for="paintbrand">局部喷漆</label>				
										<div class="am-form-group">
											 <label class="am-radio-inline">
												<input type="radio" name="ispaintpartly" value="1" data-am-ucheck  /> 是
											</label>
											<label class="am-radio-inline">
												<input type="radio" name="ispaintpartly" value="0" data-am-ucheck checked/> 否</label>
										</div>
									</div>
									<div class="am-form-group">						
										<label for="paintbrand">包含免费洗车服务</label>	
										<div class="am-form-group">
											 <label class="am-radio-inline">
												<input type="radio" name="hasfeewash" value="1" data-am-ucheck  /> 是
											</label>
											<label class="am-radio-inline">
												<input type="radio" name="hasfeewash" value="0" data-am-ucheck checked/> 否</label>
										</div>
									</div>
									<div class="am-form-group">		
										<label for="name">分节假日不同价钱</label>
							
										<div class="am-form-group">
											 <label class="am-radio-inline">
												<input type="radio" name="hasholidayprice" value="1" data-am-ucheck  /> 是
											</label>
											<label class="am-radio-inline">
												<input type="radio" name="hasholidayprice" value="0" data-am-ucheck checked/> 否</label>
										</div>
									</div>
									<div class="am-form-group">		
									<div class="am-u-sm-4">
										<label for="name">节假日折扣</label>
									</div>
									<div class="am-u-sm-8">
										<input type="number" name="holidaydiscount"  value=""
											data-mini="true" placeholder="折">
									</div>
								</div>		
						</form>
					</div>
				</dd>
			</dl>
		</section>


			<div class="am-g">
			<div class="am-u-sm-9 am-u-sm-centered">
				<a href="#" class="am-btn am-btn-secondary am-btn-block"
					onclick="doSubmit('snext')">确认无误,进入下一步</a>
			</div>
			<div class="am-u-sm-9 am-u-sm-centered" style="margin-top:0.5em"
				onclick="doSubmit('save')">
				<a href="#" class="am-btn am-btn-secondary am-btn-block">暂时保存</a>
			</div>
		</div>
	</div>
</body>
</html>
